﻿<common:LayoutAwarePage
    x:Name="pageRoot"
    x:Class="LanguageConverterTemplate.GroupedItemsPage"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    IsTabStop="false"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:LanguageConverterTemplate"
    xmlns:data="using:LanguageConverterTemplate.Data"
    xmlns:common="using:LanguageConverterTemplate.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Page.Resources>

        <!--
            Collection of grouped items displayed by this page, bound to a subset
            of the complete item list because items in groups cannot be virtualized
        -->
        <CollectionViewSource
            x:Name="groupedItemsViewSource"
            Source="{Binding Groups}"
            IsSourceGrouped="true"
            ItemsPath="AllGroups"
            d:Source="{Binding AllGroups, Source={d:DesignInstance Type=data:SampleDataSource, IsDesignTimeCreatable=True}}"/>
    </Page.Resources>

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid>
        <Grid.Background>
            <ImageBrush ImageSource="Assets/Bg.jpg"/>
        </Grid.Background>
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!-- Back button and page title -->
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
            <TextBlock x:Name="pageTitle" Text="Your App Slogan / Logo Goes Here" Grid.Column="1" Style="{StaticResource PageHeaderTextStyle}"/>
        </Grid>

        <!-- Horizontal scrolling grid used in most view states -->
        <ScrollViewer
            x:Name="itemGridScrollViewer"
            AutomationProperties.AutomationId="ItemGridScrollViewer"
            Grid.Row="1"
            Margin="0,-3,0,0"
            Style="{StaticResource HorizontalScrollViewerStyle}">

            <GridView
                x:Name="itemGridView"
                AutomationProperties.AutomationId="ItemGridView"
                AutomationProperties.Name="Grouped Items"
                Margin="100,0,0,0"
                ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
                
                SelectionMode="None"
                IsItemClickEnabled="True"
                ItemClick="ItemView_ItemClick" Height="450" HorizontalAlignment="Center" VerticalAlignment="Center">

                <GridView.ItemsPanel>
                    <ItemsPanelTemplate>
                        <VirtualizingStackPanel Orientation="Horizontal"/>
                    </ItemsPanelTemplate>
                </GridView.ItemsPanel>
                <GridView.GroupStyle>
                    <GroupStyle>
                        <GroupStyle.HeaderTemplate>
                            <DataTemplate>
                                <Grid Margin="20,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Top">
                                    <!--Added Grid-->
                                    <Grid HorizontalAlignment="Left" Width="285" Height="424" Background="{Binding bgColour}" Margin="0" Tapped="Header_Click">
                                        <Grid.RowDefinitions>
                                            
                                            <RowDefinition Height="*"/>
                                            <RowDefinition Height="90"/>
                                        </Grid.RowDefinitions>

                                        <StackPanel Background="#FF697A00" Margin="0" Orientation="Horizontal" Grid.Row="1">
                                    		<TextBlock Text="{Binding Title}"  Foreground="White" Style="{StaticResource CaptionTextStyle}" TextWrapping="Wrap" Margin="20,10,10,10" RenderTransformOrigin="0.5,0.5" FontSize="24" d:LayoutOverrides="GridBox" Padding="0" FontWeight="SemiLight" LineHeight="25.333" ScrollViewer.VerticalScrollBarVisibility="Disabled" VerticalAlignment="Center" HorizontalAlignment="Left">
                                    			<TextBlock.RenderTransform>
                                    				<CompositeTransform TranslateX="-1" TranslateY="4"/>
                                    			</TextBlock.RenderTransform>
                                    		</TextBlock>
                                    		<TextBlock Margin="10,0,0,0" Text="{Binding Subtitle}" TextWrapping="Wrap" Foreground="White" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="13.333" Visibility="Collapsed"/>
                                    	</StackPanel>

                                    	<Grid HorizontalAlignment="Left" Margin="0">
                                    		<Image  Margin="0" Source="{Binding Image}" Stretch="Fill" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                    	</Grid>
                                    </Grid>
                                </Grid>
                            </DataTemplate>
                        </GroupStyle.HeaderTemplate>
                        <GroupStyle.Panel>
                            <ItemsPanelTemplate>
                                <VariableSizedWrapGrid Orientation="Vertical" Margin="0,0,20,0"/>
                            </ItemsPanelTemplate>
                        </GroupStyle.Panel>
                    </GroupStyle>
                </GridView.GroupStyle>
            </GridView>
        </ScrollViewer>
        <!-- Vertical scrolling list only used when snapped -->
        <ScrollViewer
            x:Name="itemListScrollViewer"
            AutomationProperties.AutomationId="ItemListScrollViewer"
            Grid.Row="1"
            Visibility="Collapsed"
            Style="{StaticResource VerticalScrollViewerStyle}">

            <ListView
                x:Name="itemListView"
                AutomationProperties.AutomationId="ItemListView"
                AutomationProperties.Name="Grouped Items"
                Margin="10,-10,0,60"
                ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
                ItemTemplate="{StaticResource Standard80ItemTemplate}"
                SelectionMode="None"
                IsItemClickEnabled="True"
                ItemClick="ItemView_ItemClick">

                <ListView.GroupStyle>
                    <GroupStyle>
                        <GroupStyle.HeaderTemplate>
                            <DataTemplate>
                                <Grid Margin="7,7,0,0">
                                    <Button
                                        AutomationProperties.Name="Group Title"
                                        Content="{Binding Title}"
                                        Click="Header_Click"
                                        Style="{StaticResource TextButtonStyle}" Visibility="Collapsed"/>
                                    <Grid HorizontalAlignment="Left" Width="280" Height="300" Background="{Binding bgColour}" Margin="0" Tapped="Header_Click">
                                    	<Grid.RowDefinitions>
                                            
                                    		<RowDefinition Height="*"/>
                                    		<RowDefinition Height="90"/>
                                    	</Grid.RowDefinitions>

                                    	<StackPanel Margin="0" Orientation="Horizontal" Grid.Row="1" Background="#FF697A00">
                                    		<TextBlock Text="{Binding Title}"  Foreground="White" Style="{StaticResource CaptionTextStyle}" TextWrapping="Wrap" Margin="20,10,10,10" RenderTransformOrigin="0.5,0.5" FontSize="24" d:LayoutOverrides="GridBox" Padding="0" FontWeight="SemiLight" LineHeight="25.333" ScrollViewer.VerticalScrollBarVisibility="Disabled" VerticalAlignment="Center" HorizontalAlignment="Left">
                                    			<TextBlock.RenderTransform>
                                    				<CompositeTransform TranslateX="-1" TranslateY="4"/>
                                    			</TextBlock.RenderTransform>
                                    		</TextBlock>
                                    		<TextBlock Margin="10,0,0,0" Text="{Binding Subtitle}" TextWrapping="Wrap" Foreground="White" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="13.333" Visibility="Collapsed"/>
                                    	</StackPanel>

                                    	<Grid HorizontalAlignment="Left" Margin="0">
                                    		<Image  Margin="0" Source="{Binding Image}" Stretch="UniformToFill" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                    	</Grid>
                                    </Grid>
                                </Grid>
                            </DataTemplate>
                        </GroupStyle.HeaderTemplate>
                    </GroupStyle>
                </ListView.GroupStyle>
            </ListView>
        </ScrollViewer>

        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup>
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>

                <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridView" Storyboard.TargetProperty="Margin">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="96,0,10,56"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!--
                    The back button and title have different styles when snapped, and the list representation is substituted
                    for the grid displayed in all other view states
                -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/>
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemListScrollViewer" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridScrollViewer" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
    
</common:LayoutAwarePage>
